<%@page import="com.dxl.dao.common.context.SessionContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false"%>
<%@ include file="/WEB-INF/view/common/loginCheck.jspf" %>
<div class="easyui-panel" data-options="fit:true,footer:'#stockEditBtns'" style="padding:10px;">
    <form id="stockEditForm" method="post">
		 <table style="width:100%">
		 	 <tr>
                 <td>区域:</td>
                 <td>
                	<input type="hidden" name="id" value="${entity.id}" />
                 	<input id="areaSelectBox" style="width:250px;" class="easyui-combobox" name="areaId" value="${entity.areaId}" data-options="required:true,valueField:'id',textField:'name',url:'${ROOT}/area/listAll'" />
                 </td>
             </tr>
             <tr>
                 <td>业务员:</td>
                 <td>
                 	<input id="userSelectBox" style="width:250px;" class="easyui-combobox" name="userId" value="${entity.userId}" data-options="required:true,valueField:'id',textField:'name',url:'${ROOT}/user/listAll'" />
                 </td>
             </tr>
             <tr>
                 <td>产品:</td>
                 <td>
                 	<input id="selectedProdIdFromDlg" type="hidden" name="prodSkuId" value="${entity.prodSkuId}" />
                 	<input id="selectedProdNameFromDlg" class="easyui-textbox" readonly="readonly" type="text" data-options="required:true" style="width:300px;" value="<c:if test='${product != null}' >${product.name}[${productSku.color}][${productSku.taste}]</c:if>" />
                 	<a href="javascript:void(0)" title="选择产品" class="easyui-linkbutton" onclick="showProdSelectionDlg();" data-options="iconCls:'icon-ok'"></a>
                 	<a href="javascript:void(0)" title="清空产品" class="easyui-linkbutton" onclick="clearProdInfo();" data-options="iconCls:'icon-no'"></a>
                 </td>
             </tr>
             <tr>
                 <td>固定库存:</td>
                 <td>
                 	<input class="easyui-numberspinner" style="width:250px;" type="text" name="fixedNum" value="${entity.fixedNum}" data-options="required:true,min:0,precision:0" />
                 </td>
             </tr>
             <tr>
                 <td>新增库存:</td>
                 <td>
                 	<input class="easyui-numberspinner" style="width:250px;" type="text" name="addNum" value="${entity.addNum}" data-options="min:0,precision:0" />
                 </td>
             </tr>
             <tr>
                 <td>备注:</td>
                 <td>
                 	<input class="easyui-textbox" style="width:300px;" type="text" name="remark" value="${entity.remark}" />
                 </td>
             </tr>
         </table>
	</form>
</div>

<div id="prodSelectionFromDlg" 
	class="easyui-dialog" 
	title="选择商品" 
	style="width:900px;height:500px;"
    data-options="iconCls:'icon-search',resizable:false,modal:true,closed:true">
</div>
    
<t:permission codes="STOCK-VIEW,STOCK-MODIFY">    
<div id="stockEditBtns" style="text-align:right;padding:2px;">
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="saveStock();">保存</a>
</div>
</t:permission>

<script type="text/javascript">
	$(function () {
		$('#stockEditForm').form({
		    url:'${ROOT}/stock/save?_rt=' + new Date().getTime(),
		    ajax: true,
		    onSubmit: function() {
		    	return $(this).form('enableValidation').form('validate');
		    },
		    success:function(data) {
		    	var json = eval('(' + data + ')');
				if (json.success) {
					APP.message('保存成功');
		        	$('#stockEditDlg').dialog('close');
		        	$('#stockDataListTable').datagrid('reload');
					$('#stockDataListTable').datagrid('clearSelections');
		        	$('#stockDataListTable').datagrid('clearChecked');
		        } else {
		        	 APP.error(json.msg);
		        }
		    }
		});
	});
	
	function saveStock() {
		$('#stockEditForm').submit();
	}
	
	function closeStockEditDlg() {
		$('#stockEditDlg').dialog('close');
	}
	
	function clearProdInfo() {
		$('#selectedProdIdFromDlg').val('');
		$('#selectedProdNameFromDlg').textbox('setText', '');
	}
	
	function showProdSelectionDlg() {
		var url = '${ROOT}/product/selectSku';
		$('#prodSelectionFromDlg').dialog('open').dialog('refresh', url)
	}
</script>